/*
 * @Author: zsk
 * @Date: 2021-12-11 11:40:38
 * @LastEditTime: 2021-12-12 14:25:09
 * @LastEditors: zsk
 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * @FilePath: /data-and-structure-lv/02/insertion/insertion-sort.c
 */
#include <stdio.h>

typedef int ElementType;

void insertion_sort(ElementType *a,int length)
{
    for (int j = 1; j < length; j++)
    {
        /* code */
        ElementType key=a[j];
        int i=j-1;
        while (i>=0 && a[i]>key)
        {
            /* code */
            a[i+1]=a[i];
            i=i-1;
        }
        a[i+1]=key;
        
    }
    
}

void main()
{
    ElementType a[]={5,2,4,6,1,3};
    int length = 6;
    insertion_sort(a,length);
    for (int i = 0; i < length; i++)
    {
        /* code */
        printf("%d ",a[i]);
    }
    printf("\n");
    
}